home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / GNUUCP_2 / SOURCE / UUMISC.C < prev    next >
Text File  |  1990-05-23  |  8KB  |  315 lines

  1. /*
  2.  * @(#)uumisc.c 1.6 87/09/29    Copyright 1987 Free Software Foundation, Inc.
  3.  *
  4.  * Copying and use of this program are controlled by the terms of the
  5.  * GNU Emacs General Public License.
  6.  *
  7.  * uumisc.c
  8.  *
  9.  * Miscellaneous uucp variables and routines which are used by several
  10.  * uucp main programs.
  11.  */
  12. #include "includes.h"        /* System include files, system dependent */
  13. #include "uucp.h"        /* Uucp definitions and parameters */
  14.  
  15. char    Myname[MAX_HOST];    /* Our uucp hostname, set from usenet.ctl */
  16. char    Mynamealias[MAX_HOST];    /* Our uucp hostname, set from usenet.ctl */
  17. char    Forwarder[MAX_HOST];
  18. char    host_name[MAX_HOST] = "gnuucp";    /* Other guy's host name */
  19. char    *uuControl;        /* Control file name */
  20. char    who[NAMESIZE] = "-";    /* Who sent us a file */
  21. char    *Spool;            /* Spool directory root name */
  22. char    *Alias;            /* Directory where aliases are kept */
  23. char    *Sysfile;        /* L.sys file */
  24. char    *Userfile;        /* USERFILE */
  25. char    *Pubdir;        /* Public Directory */
  26. char    *Logfile;        /* Logging file */
  27. char    *MLogfile;        /* Logging file for mail */
  28. char    *Username;        /* Username for single user machine */
  29. char    *Timezone;        /* Timezone string ("EDT", "PST"....) */
  30. char    *UUCPlogname;    /* Login name for UUCP */
  31. char    *UUCPpasswd;    /* Password for UUCP */
  32. char    *Mail;            /* Directory where mail is delivered */
  33. long    ByteTimeout;    /* Lenght of time xgetc waits for a char (in secs) */
  34. long    ConnectWait;    /* Max time we wait after dialing */
  35.  
  36. int    debug = -1;        /* -1 indicates ctl file should set it */
  37. int    ourpid = 0;        /* Our process ID */
  38. int    logfd;            /* file desc of uucp logfile */
  39.  
  40. struct port *ports, *porttail;    /* Chain of serial port definitions */
  41.  
  42. #ifdef VMS
  43. void *malloc();
  44. #else
  45. #ifndef MAC
  46. char    *malloc();
  47. #endif
  48. #endif
  49. char    *gimmestring();        /* Forward declaration */
  50.  
  51. /*
  52.  * Read the control file and grab a few parameters.
  53.  */
  54. read_params(ctl)
  55.     char *ctl;
  56. {
  57.     FILE    *fd;
  58.     char    buf[MAX_CTLLINE];
  59.     register struct port *newport;
  60.     register char *cmd;
  61.     register char    *p;
  62.  
  63.     if (ctl) {
  64.         /* Remove any possible setuid if user spec'd a control file */
  65.         /* FIXME: this is system dependent....sigh
  66.         setuid(getuid()); */
  67.     } else {
  68.         /* Use the system default control file */
  69.         ctl = sysdep_control;
  70.     }
  71.     uuControl = ctl;
  72.     if (! (fd = fopen(ctl, "r"))) {
  73.         printf("Can't find configuration file %s\n", ctl);
  74.         return FAIL;
  75.     }
  76.  
  77.     /* find path to inbound news */
  78.     Spool = "";
  79.     Alias = "";
  80.     Mail = "";            
  81.     Sysfile = "";
  82.     Username = "";
  83.     Userfile = "";
  84.     Pubdir = "";
  85.     Logfile = "";
  86.     MLogfile = "";
  87.     UUCPlogname = "";
  88.     UUCPpasswd = "";
  89.     Timezone = "";
  90.     strcpy(Myname, "");
  91.     strcpy(Mynamealias, "");
  92.     strcpy(Forwarder, "");
  93.     ByteTimeout = BYTE_TIMEOUT;
  94.     ConnectWait = CONNECT_WAIT;
  95.     while ((long)NULL != (long)fgets(buf, sizeof buf, fd)) {
  96.  
  97.         cmd = strtok(buf, CTL_DELIM);
  98.         if (!cmd) continue;        /* Skip blank lines */
  99.         for (p = cmd; *p; p++)
  100.             if (isupper(*p)) *p = tolower(*p);
  101.  
  102.         /* Now figure out which one it is */
  103.  
  104.         if (strcmp(cmd, "alias") == 0) {
  105.             Alias = gimmestring();
  106.         } else if (strcmp(cmd, "spool") == 0) {
  107.             Spool = gimmestring();
  108.         } else if (strcmp(cmd, "sysfile") == 0) {
  109.             Sysfile = gimmestring();
  110.         } else if (strcmp(cmd, "username") == 0) {
  111.             Username = gimmestring();
  112.         } else if (strcmp(cmd, "uucplogname") == 0) {
  113.             UUCPlogname = gimmestring();
  114.         } else if (strcmp(cmd, "uucppasswd") == 0) {
  115.             UUCPpasswd = gimmestring();
  116.         } else if (strcmp(cmd, "mail") == 0) {
  117.             Mail = gimmestring();
  118.         } else if (strcmp(cmd, "userfile") == 0) {
  119.             Userfile = gimmestring();
  120.         } else if (strcmp(cmd, "pubdir") == 0) {
  121.             Pubdir = gimmestring();
  122.         } else if (strcmp(cmd, "logfile") == 0) {
  123.             Logfile = gimmestring();
  124.         } else if (strcmp(cmd, "timezone") == 0) {
  125.             Timezone = gimmestring();
  126.         } else if (strcmp(cmd, "mlogfile") == 0) {
  127.             MLogfile = gimmestring();
  128.         } else if (strcmp(cmd, "nodename") == 0) {
  129.             strcpy(Myname, strtok((char *)NULL, CTL_DELIM) ) ;
  130.         } else if (strcmp(cmd, "nodenamealias") == 0) {
  131.             strcpy(Mynamealias, strtok((char *)NULL, CTL_DELIM) ) ;
  132.         } else if (strcmp(cmd, "forwarder") == 0) {
  133.             strcpy(Forwarder, strtok((char *)NULL, CTL_DELIM) ) ;
  134.         }
  135.           else if (strcmp(cmd, "debug") == 0) {
  136.             if (debug < 0) {
  137.                 debug = atoi(strtok((char *)NULL, CTL_DELIM));
  138.             }
  139.         }
  140.           else if (strcmp(cmd, "bytetimeout") == 0) {
  141.                 {
  142.                     ByteTimeout = atoi(strtok((char *)NULL, CTL_DELIM));
  143.             }
  144.         }
  145.           else if (strcmp(cmd, "connectwait") == 0) {
  146.                 {
  147.                     ConnectWait = atoi(strtok((char *)NULL, CTL_DELIM));
  148.             }
  149.         } else if (strcmp(cmd, "port") == 0) {
  150.             newport = (struct port *)malloc(sizeof *newport);
  151.             p = strtok((char *)NULL, CTL_DELIM);
  152.             strcpy(newport->portname, p);
  153.             p = strtok((char *)NULL, CTL_DELIM);
  154.             strcpy(newport->modemname, p);
  155.             p = strtok((char *)NULL, CTL_DELIM);
  156.             strcpy(newport->devname, p);
  157.             p = strtok((char *)NULL, CTL_DELIM);
  158.             newport->baud = atol(p);
  159.             /* Add it to the end of the chain */
  160.             newport->chain = (struct port *)0;
  161.             if (ports)
  162.                 porttail->chain = newport;
  163.             else
  164.                 ports = newport;
  165.             porttail = newport;
  166.         }
  167.     }
  168.  
  169.     fclose(fd);
  170.     return SUCCESS;
  171. }
  172.  
  173. /* Scan out next arg as a string, return it or NULL if none there. */
  174. char *
  175. gimmestring()
  176. {
  177.     register char *p, *q;
  178.  
  179.     p = strtok((char *)NULL, CTL_DELIM);
  180.     if (p == NULL)
  181.         return p;
  182.     q = (char *)malloc(strlen(p)+1);
  183.     strcpy(q, p);
  184.     return q;
  185. }
  186.  
  187. /*
  188.  * Scan out an "argv" from a blank-separated string.
  189.  *
  190.  * Result is argc, or -1 if there are too many args.
  191.  */
  192. int
  193. getargs(string, argv, maxargc)
  194.     char    *string;
  195.     char    **argv;
  196.     int    maxargc;
  197. {
  198.     int    argc = 0;
  199.  
  200.     while (*string == ' ') string++;
  201.  
  202.     for (; *string; ) {
  203.         argv[argc++] = string;        /* Record position */
  204.         if (argc >= maxargc) return -1;
  205.         while (*string && *string != ' ') string++;
  206.         if (*string == '\0') break;
  207.         *string++ = '\0';        /* Null terminate it */
  208.         while (*string == ' ') string++;
  209.     }
  210.  
  211.     argv[argc] = (char *)0;            /* Null after last one */
  212.     return argc;
  213. }
  214.  
  215. /*
  216.  * Log file writing subroutine.
  217.  *
  218.  * Makes incredibly ugly log entries that look *just like* Unix uucp's
  219.  * incredibly ugly log entries.
  220.  *
  221.  * Once we don't care about compatability, we should do this much better.
  222.  */
  223. logit(one, two)
  224.     char *one, *two;
  225. {
  226.     char logbuf[(NAMESIZE*4)+SLOP+50];    /* Temp buffer for logs */
  227.     int len;
  228.  
  229.     if (logfd <= 0) {
  230.         /* Open the log file if not already open */
  231.         if (Logfile == 0 || *Logfile == 0)
  232.             return;        /* If none specified, no logging. */
  233.         logfd = open(Logfile, O_CREAT|O_WRONLY|O_APPEND|O_TEXT);
  234.         if (logfd < 0) {
  235.             if (DEBUG_LEVEL(0)) perror(Logfile);
  236.             exit(EXIT_ERR);
  237.         }
  238.     }
  239.  
  240.     sprintf(logbuf, "%s %s (%s) %s (%s)\n",
  241.         who, host_name, time_and_pid(), one, two);
  242.  
  243.     DEBUG(0, "%s", logbuf);
  244.  
  245.     len = strlen(logbuf);
  246.     if (len != write(logfd, logbuf, len)) {
  247.         if (DEBUG_LEVEL(0)) {
  248.             fprintf(stderr, "Can't write to log, terminating!\n");
  249.             perror(Logfile);
  250.         }
  251.         exit(EXIT_ERR);        /* Terminate if we can't log */
  252.     }
  253.  
  254. #ifdef LOGCLOSE
  255.     if (close(logfd) != 0) {
  256.         if (DEBUG_LEVEL(0)) {
  257.             fprintf(stderr, "Can't close log, terminating!\n");
  258.             perror(Logfile);
  259.         }
  260.         exit(EXIT_ERR);        /* Terminate if we can't log */
  261.     }
  262.     logfd = -1;
  263. #endif
  264. }
  265.  
  266. mlogit(one, two)
  267.     char *one, *two;
  268. {
  269.     char logbuf[(NAMESIZE*4)+SLOP+50];    /* Temp buffer for logs */
  270.     int len;
  271.  
  272.     if (logfd <= 0) {
  273.         /* Open the log file if not already open */
  274.         if (Logfile == 0 || *Logfile == 0)
  275.             return;        /* If none specified, no logging. */
  276.         logfd = open(MLogfile, O_CREAT|O_WRONLY|O_APPEND|O_TEXT);
  277.         if (logfd < 0) {
  278.             if (DEBUG_LEVEL(0)) perror(MLogfile);
  279.             exit(EXIT_ERR);
  280.         }
  281.     }
  282.  
  283.     sprintf(logbuf, "%s %s (%s) %s (%s)\n",
  284.         who, host_name, time_and_pid(), one, two);
  285.  
  286.     DEBUG(0, "%s", logbuf);
  287.  
  288.     len = strlen(logbuf);
  289.     if (len != write(logfd, logbuf, len)) {
  290.         if (DEBUG_LEVEL(0)) {
  291.             fprintf(stderr, "Can't write to log, terminating!\n");
  292.             perror(MLogfile);
  293.         }
  294.         exit(EXIT_ERR);        /* Terminate if we can't log */
  295.     }
  296.  
  297. #ifdef LOGCLOSE
  298.     if (close(logfd) != 0) {
  299.         if (DEBUG_LEVEL(0)) {
  300.             fprintf(stderr, "Can't close log, terminating!\n");
  301.             perror(MLogfile);
  302.         }
  303.         exit(EXIT_ERR);        /* Terminate if we can't log */
  304.     }
  305.     logfd = -1;
  306. #endif
  307. }
  308.  
  309. void
  310. cuserid(str)
  311. char *str;
  312. {
  313.     strcpy(str, Username);
  314.     }
  315.